<?php
/**
 * 更新记录：
 * 	2022-05-16 新增FastDFS.id
 */
require '../../vendor/autoload.php';

use utils\ConfigReader;
use utils\HttpHeader;
use utils\PathTool;
use utils\SysTool;
use utils\WebWriter;
use utils\StringTool;

$head = new HttpHeader();

$id          = $head->param("id");
$blockIndex  = $head->paramInt("blockIndex");
$blockOffset = $head->paramInt("blockOffset");
$blockSize   = $head->paramInt("blockSize");
$pathSvr     = $head->param("pathSvr");
$object_id   = $head->param("object_id");
$pathSvr     = PathTool::urldecode_path($pathSvr);

if (empty($id)||
    empty($blockIndex)||
    strlen($blockOffset) < 1||
    empty($blockSize)||
    empty($pathSvr) ) 
{
	header('HTTP/1.1 500 param null');
	return;
}

header("Cache-Control: public");
header("Content-Type: application/octet-stream");
header("Content-Length: $blockSize");

//windows系统中需要将中文转换为gb2312
$sys = new SysTool();
$pathSvr = $sys->to_gbk($pathSvr);

if( StringTool::iequals(ConfigReader::storageType(),"FastDFS")) $pathSvr = $object_id;
if(StringTool::iequals(ConfigReader::storageType(), "Minio")) $pathSvr = $object_id;
if(StringTool::iequals(ConfigReader::storageType(), "OSS")) $pathSvr = $object_id;

#清空缓存区
ob_clean();

$ww = new WebWriter();
$ww->write($pathSvr,$blockOffset,$blockSize);
?>